package com.lou1052.redis.jedis.ext.client.shard;

import com.lou1052.core.serializer.Serializer;
import com.lou1052.redis.jedis.api.JedisApi;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.util.Hashing;
import redis.clients.util.IPool;

import java.util.List;
import java.util.function.Function;
import java.util.regex.Pattern;

/**
 *
 * Created with IntelliJ IDEA.
 * User: liuqing
 * Date: 2015/10/25
 * Time: 12:10
 * To change this template use File | Settings | File Templates.
 */
public class ShardedJedisExt extends ShardedJedis implements JedisApi {


    public void setSerializerFunction(Function<String, Serializer> serializerFunction) {
        this.serializerFunction = serializerFunction;
    }
    @Override
    public Serializer getSerializer(String key) {
        return serializerFunction.apply(key);
    }

    @Override
    public void setDataSource(IPool jedisPool) {
        this.dataSource = jedisPool;
    }

    protected ShardedJedisExt(){}

    public ShardedJedisExt(List<JedisShardInfo> shards, Function<String, Serializer> serializerFunction) {
        super(shards);
        this.serializerFunction = serializerFunction;
    }

    public ShardedJedisExt(List<JedisShardInfo> shards, Hashing algo, Function<String, Serializer> serializerFunction) {
        super(shards, algo);
        this.serializerFunction = serializerFunction;
    }

    public ShardedJedisExt(List<JedisShardInfo> shards, Hashing algo, Pattern keyTagPattern, Function<String, Serializer> serializerFunction) {
        super(shards, algo, keyTagPattern);
        this.serializerFunction = serializerFunction;
    }

    public ShardedJedisExt(List<JedisShardInfo> shards, Pattern keyTagPattern, Function<String, Serializer> serializerFunction) {
        super(shards, keyTagPattern);
        this.serializerFunction = serializerFunction;
    }

    public ShardedJedisExt(List<JedisShardInfo> shards) {
        super(shards);
    }

    public ShardedJedisExt(List<JedisShardInfo> shards, Hashing algo) {
        super(shards, algo);
    }

    public ShardedJedisExt(List<JedisShardInfo> shards, Hashing algo, Pattern keyTagPattern) {
        super(shards, algo, keyTagPattern);
    }

    public ShardedJedisExt(List<JedisShardInfo> shards, Pattern keyTagPattern) {
        super(shards, keyTagPattern);
    }
}
